package com.woniuxy.thred.state;

/**
 * description: PriorityTest <br>
 * date: 2022/2/5 11:01 下午 <br>
 * author: shesaifei <br>
 * version: 1.0 <br>
 */

/**
 * 线程的优先级 1-10
 * 1、NORM_PRIORITY   5 默认
 * 2、MIN_PRIORITY    1
 * 3、MAX_PRIORITY    10
 * 概率，不代表绝对的先后顺序
 */
public class PriorityTest {
    public static void main(String[] args) {
        System.out.println(Thread.currentThread().getPriority());

        MyPriority map = new MyPriority();

        Thread t1 = new Thread(map, "adidas");
        Thread t2 = new Thread(map, "NIKE");
        Thread t3 = new Thread(map, "回力");
        Thread t4 = new Thread(map, "李林");
        Thread t5 = new Thread(map, "双星");
        Thread t6 = new Thread(map, "puma");

        //设置优先级在启动前
        t1.setPriority(Thread.MAX_PRIORITY);
        t2.setPriority(Thread.MAX_PRIORITY);
        t3.setPriority(Thread.MAX_PRIORITY);
        t4.setPriority(Thread.MIN_PRIORITY);
        t5.setPriority(Thread.MIN_PRIORITY);
        t6.setPriority(Thread.MIN_PRIORITY);


        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();
        t6.start();
    }
}

class MyPriority implements Runnable {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "-->" + Thread.currentThread().getPriority());
        Thread.yield();
    }
}